﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WMS.FC.Application.Location.Interface;
using WMS.FC.Application.System;
using WMS.FC.Domain.DataTransferObject.Location;
using WMS.FC.Domain.DataTransferObject.System;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.Repository;
using WMS.FC.Domain.Service.Location.Interface;

namespace WMS.FC.Application.Location
{
    public class LocationService : ServiceBase, ILocationService
    {
        protected readonly IAddLocationService addLocationService;

        public LocationService(
            ILogger<ServiceBase> logger,
            IOptions<WmsSettings> options,
            IMapper mapper,
            IUnitOfWork unitOfWork,
            IAddLocationService addLocationService)
            : base(logger, options, mapper, unitOfWork)
        {
            this.addLocationService = addLocationService;
        }

        public async Task<ResponseBase> AddLocation(AddDataDTO<AddLocationDTO> dTO)
        {
            var response = new ResponseBase();
            try
            {
                var result = await unitOfWork.UseTranAsync(async () =>
                {
                    return await addLocationService.AddLocation(dTO.Value, dTO.UserInfo);
                });

                response = response.TransferResult(result);
            }
            catch (Exception ex)
            {
                return response.Exception(ex);
            }

            return response;
        }
    }
}
